home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / grafik / 3d & render tools / irit / contrib / compgrap / transforms / 2ddemo.irt < prev    next >
Encoding:
Text File  |  1996-07-16  |  4.4 KB  |  171 lines

  1. #
  2. # Demos for 2D Transformations.
  3. #
  4. #                    (c) Gershon Elber, July 1995
  5. #
  6.  
  7. comment $
  8. pause = procedure():
  9.     printf("Press return to continue:", nil());
  10. $
  11.  
  12. # include("house");
  13. House = load("house");
  14. House1 = House * tx( 0.225 ) * ty( 0.65 ) * sc( 2.0 );
  15.  
  16. Axes = list( ctlpt( E2, -2, 0 ) + ctlpt( E2, 2, 0 ),
  17.          ctlpt( E2, 0, -2 ) + ctlpt( E2, 0, 2 ) );
  18. color( Axes, yellow );
  19. attrib( Axes, "dwidth", 2 );
  20.  
  21. #
  22. # 2D transformation's demo.
  23. #
  24. view_mat = tz( 0.1 );
  25. interact( list( view_mat, axes, House1 ) );
  26.  
  27. #
  28. # SCALING uniformly.
  29. #
  30. scl = cbspline( 3,
  31.             list( ctlpt( E1, 1 ),
  32.               ctlpt( E1, 3 ),
  33.               ctlpt( E1, 0 ),
  34.               ctlpt( E1, 0 ),
  35.               ctlpt( E1, 1 ) ),
  36.             list( KV_OPEN ) );
  37. scl = creparam( scl, 0, 1 );
  38. attrib( House1, "animation", list( scl ) );
  39. interact( list( Axes, House1 ) );
  40.  
  41. #
  42. # SCALING in X and Y operations.
  43. #
  44. scl = cbspline( 3,
  45.         list( ctlpt( E1, 1 ),
  46.               ctlpt( E1, 3 ),
  47.               ctlpt( E1, 0 ),
  48.               ctlpt( E1, 0 ),
  49.               ctlpt( E1, 1 ) ),
  50.         list( KV_OPEN ) );
  51. scl_x = creparam( scl, 0, 0.5 );
  52. scl_y = creparam( scl, 0.5, 1 );
  53. attrib( House1, "animation", list( scl_x, scl_y ) );
  54. interact( list( Axes, House1 ) );
  55.  
  56. #
  57. # SCALING with NEGATIVE values.
  58. #
  59. scl = cbspline( 2,
  60.                 list( ctlpt( E1, 1 ),
  61.                       ctlpt( E1, -1 ) ),
  62.                 list( KV_OPEN ) );
  63. scl_x = creparam( scl, 0, 0.5 );
  64. scl_y = creparam( scl, 0.5, 1 );
  65. attrib( House1, "animation", list( scl_x, scl_y ) );
  66. interact( list( Axes, House1 ) );
  67.  
  68. #
  69. # ROTATION in the plane.
  70. #
  71. rot_z = cbspline( 2,
  72.                   list( ctlpt( E1, 0 ),
  73.                         ctlpt( E1, 360 ),
  74.                         ctlpt( E1, 0 ) ),
  75.                   list( KV_OPEN ) );
  76. rot_z = creparam( rot_z, 0, 1 );
  77. attrib( House1, "animation", list( rot_z ) );
  78. interact( list( Axes, House1 ) );
  79.  
  80. #
  81. # TRANSLATION in the plane.
  82. #
  83. mov_xyz = cbspline( 3,
  84.                     list( ctlpt( E3,  0.0,  0.0, 0 ),
  85.                           ctlpt( E3,  0.7, -0.7, 0 ),
  86.                           ctlpt( E3,  0.7,  0.7, 0 ),
  87.                           ctlpt( E3, -0.7, -0.7, 0 ),
  88.                           ctlpt( E3,  0.0,  0.7, 0 ),
  89.                           ctlpt( E3, -0.7,  0.7, 0 ),
  90.                           ctlpt( E3,  0.0,  0.0, 0 ) ),
  91.                     list( KV_OPEN ) );
  92. mov_xyz = creparam( mov_xyz, 0, 1 );
  93. attrib( House1, "animation", list( mov_xyz ) );
  94. interact( list( Axes, House1 ) );
  95.  
  96. #
  97. # COMPOSITION of transformtions.
  98. #
  99. House2 = House1 * trans( vector( 0.25, 0.25, 0.0 ) );
  100.  
  101. Trans1 = trans( vector( -0.1, -0.15, 0.0 ) );
  102. Rot1 = rotz( 30 );
  103. Trans2 = trans( vector( 0.1, 0.15, 0.0 ) );
  104.  
  105. interact( list( Axes, House2 ) );
  106.  
  107. interact( list( Axes, House2 * Trans1 ) );
  108.  
  109. interact( list( Axes, House2 * Trans1 * Rot1 ) );
  110.  
  111. interact( list( Axes, House2 * Trans1 * Rot1 * Trans2 ) );
  112.  
  113. #
  114. # Rotate by SHEAR
  115. #
  116. HouseFrame = poly( list( point( 0.0, 0.0, 0 ),
  117.              point( 0.5, 0.0, 0 ),
  118.              point( 0.5, 0.8, 0 ),
  119.              point( 0.0, 0.8, 0 ),
  120.              point( 0.0, 0.0, 0 ) ),
  121.             true );
  122. color( HouseFrame, cyan );
  123. attrib( HouseFrame, "dwidth", 3 );
  124.  
  125. House3 = list( House2, HouseFrame ) * tx( -0.25 ) * ty( -0.35 );
  126. interact( list( House3, Axes ) );
  127.  
  128. Theta = 65 * Pi / 180;
  129. XVal = -tan( Theta / 2 );
  130. YVal = sin( Theta );
  131. Shear1 = homomat( list( list( 1, XVal, 0, 0 ),
  132.             list( 0, 1, 0, 0 ),
  133.             list( 0, 0, 1, 0 ),
  134.             list( 0, 0, 0, 1 ) ) );
  135. Shear2 = homomat( list( list( 1, 0, 0, 0 ),
  136.             list( sin( Theta ), 1, 0, 0 ),
  137.             list( 0, 0, 1, 0 ),
  138.             list( 0, 0, 0, 1 ) ) );
  139. Shear3 = Shear1;
  140.  
  141. interact( list( House3 * Shear1, Axes ) );
  142.  
  143. interact( list( House3 * Shear1 * Shear2, Axes ) );
  144.  
  145. interact( list( House3 * Shear1 * Shear2 * Shear3, Axes ) );
  146.  
  147. for ( i = 0, 1, 100,
  148.       XVal = -tan( Theta * i / 200 ):
  149.       view( list( House3 * 
  150.           homomat( list( list( 1, XVal, 0, 0 ),
  151.                              list( 0, 1, 0, 0 ),
  152.                               list( 0, 0, 1, 0 ),
  153.                          list( 0, 0, 0, 1 ) ) ),
  154.           Axes ), on ) );
  155. for ( i = 0, 1, 100,
  156.       YVal = sin( Theta * i / 100 ):
  157.       view( list( House3 * Shear1 *
  158.           homomat( list( list( 1, 0, 0, 0 ),
  159.                              list( YVal, 1, 0, 0 ),
  160.                               list( 0, 0, 1, 0 ),
  161.                          list( 0, 0, 0, 1 ) ) ),
  162.           Axes ), on ) );
  163. for ( i = 0, 1, 100,
  164.       ZVal = -tan( Theta * i / 200 ):
  165.       view( list( House3 * Shear1 * Shear2 *
  166.           homomat( list( list( 1, ZVal, 0, 0 ),
  167.                              list( 0, 1, 0, 0 ),
  168.                               list( 0, 0, 1, 0 ),
  169.                          list( 0, 0, 0, 1 ) ) ),
  170.           Axes ), on ) );
  171.